package chwgigs_jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class EX02_AccountDAO implements EX02_IAccountDAO {
     
	private final String DRV ="oracle.jdbcdriver.OracleDriver";
	private final String URL ="jdbc: oracle:thin:chwgigs/chwgigs@112.216.253.125:1521:xe)";
	private String insertSQL = "insert into EXAccount values (?,?,?,sysdate)";
	private String selectSQL = "select * from EXAccount order by mno desc" ;
	private String updateSQL = "update EXAccount set passwd = ?, name = ?, email = ?, regdate=sysdate  where mno=?";
	private String deleteSQL = "delete EXAccount  where mno = ?";   // where절을 안쓰면 싹 다 지워지기 때문에 반드시 where절을 쓴다.         
	@Override
	public boolean insertAccount(EX02_AccountVO c) {
		Connection conn = null;
		PreparedStatement pstmt = null;
		boolean result = false;
	try{
		conn=this.openDatabase();
		pstmt=conn.prepareStatement(insertSQL);
		pstmt.setInt(1,c.getAid());
		pstmt.setInt(2,c.getBalance());
		pstmt.setString(3,c.getDateCreated());
		pstmt.setDouble(4,c.getInterestRate());
		
		pstmt.executeUpdate();
		result=true;
		
		
	}catch (Exception ex){
		ex.printStackTrace();
	}finally{
		this.closeDatabase(conn,pstmt,null);
	}
	 return result;
	}
	
	private Connection openDatabase(){
		try{
			Class.forName(DRV);
			return DriverManager.getConnection(URL);
		}catch (Exception e){
			e.printStackTrace();
		} return null;
	}
	
	private void closeDatabase (Connection c,PreparedStatement p,ResultSet r){
		 if (r != null) try{r.close(); r = null;} catch(Exception e){}
	      if (p != null) try{p.close(); p = null;} catch(Exception e){}
	      if (c != null) try{c.close(); c = null;} catch(Exception e){}
	   }
		
	
	
	
	
	
	
	
	
	
	
	
	
}//


